package shuashuami.hb.com.http;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import shuashuami.hb.com.manager.HbAppManager;

/**
 * <b>类   名：</b>${TYPE_NAME} <br/>
 * <b>类描述：</b> <br/>
 * <b>创建人：</b>zhangqi<br/>
 * <b>创建时间：</b>2017/6/28<br/>
 * <b>修改人：</b>zhangqi<br/>
 * <b>修改时间：</b>2017/6/28<br/>
 * <b>修改备注：</b><br/>
 *
 * @version 1.0.0<br/>
 */
public class HttpMethods {

    // 用户注册第二步
    public static void register2(final HttpOnNextListener listener, String mobile, String password, String username, String realname
            , String qq, String email, String identify, String parent_id) {
        int type = HbAppManager.getInstance().getTypeValue();
        Map<String, String> map = new HashMap<>();
        map.put("type", type + "");
        map.put("mobile", mobile);
        map.put("password", password);
        map.put("username", username);
        map.put("realname", realname);
        map.put("qq", qq);
        map.put("email", email);
        map.put("identify", identify);
        map.put("parent_id", parent_id);

        HttpUtils.doPost(URLs.register2, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //获取验证码
    public static void getCode(final HttpOnNextListener listener, String mobile, String act) {
        int type = HbAppManager.getInstance().getTypeValue();
        Map<String, String> map = new HashMap<>();
        map.put("type", type + "");
        map.put("mobile", mobile);
        map.put("act", act);
        HttpUtils.doPost(URLs.bindGetCode, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    if (response.code() == 200) {
                        listener.onNext(response.body().string());
                    }
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    // 用户注册第一步
    public static void register1(final HttpOnNextListener listener, String mobile, String captcha, String password) {
        int type = HbAppManager.getInstance().getTypeValue();
        Map<String, String> map = new HashMap<>();
        map.put("type", type + "");
        map.put("mobile", mobile);
        map.put("captcha", captcha);
        map.put("password", password);

        HttpUtils.doPost(URLs.getRegister1(), map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }


    //微信登陆
    public static void weichartLogin(final HttpOnNextListener listener, String wx_sn, String avatar) {
        int type = HbAppManager.getInstance().getTypeValue();
        Map<String, String> map = new HashMap<>();
        map.put("type", type + "");
        map.put("wx_sn", wx_sn);
        map.put("avatar", avatar);
        map.put("platform", "Wechat");
        HttpUtils.doPost(URLs.weiChartLogin, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //登录
    public static void login(final HttpOnNextListener listener, String mobile, String password) {
        int type = HbAppManager.getInstance().getTypeValue();
        Map<String, String> map = new HashMap<>();
        map.put("type", type + "");
        map.put("mobile", mobile);
        map.put("password", password);
        HttpUtils.doPost(URLs.login, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //绑定手机号码
    public static void bindPhoneNum(final HttpOnNextListener listener, String mobile, String captcha) {
        int type = HbAppManager.getInstance().getTypeValue();
        Map<String, String> map = new HashMap<>();
        map.put("type", type + "");
        map.put("mobile", mobile);
        map.put("captcha", captcha);
        map.put("platform", "Wechat");
        HttpUtils.doPost(URLs.bindPhoneNum, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //完善用户信息
    public static void cPerfectData(final HttpOnNextListener listener, String phone, String password,
                                    String realName, String qq, String email, String recommenderId,
                                    String agentId, String sn, String hasAgentnum, String username, String identify) {
        int type = HbAppManager.getInstance().getTypeValue();
        Map<String, String> map = new HashMap<>();
        map.put("type", type + "");
        map.put("mobile", phone);
        map.put("password", password);
        map.put("realname", realName);
        map.put("platform", "Wechat");
        map.put("qq", qq);
        map.put("email", email);
        map.put("hasAgentnum", hasAgentnum);
        map.put("parent_id", recommenderId);
        if (hasAgentnum.equals("1")) {
            map.put("agentnum", agentId);
        }
        map.put("username", username);
        map.put("wx_sn", sn);
        map.put("identify", identify);

        HttpUtils.doPost(URLs.completeUserInfo, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //刷手分销中心
    public static void distributionCenter(final HttpOnNextListener listener, String type, String brushId, String page, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("type", type);
        map.put("brushId", brushId);
        map.put("page", page);
        map.put("size", size);

        HttpUtils.doPost(URLs.distributionCenter, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //刷手分销中心
    public static void distributionCenterYOngjin(final HttpOnNextListener listener, String brushId) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brushId);

        HttpUtils.doPost(URLs.distributionCenterYOngjin, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }


    //刷手w我的刷手
    public static void recommendListc(final HttpOnNextListener listener, String brushId, String page, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brushId);
        map.put("page", page);
        map.put("size", size);

        HttpUtils.doPost(URLs.recommendListc, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //刷手 代理申请
    public static void agentApplyc(final HttpOnNextListener listener, String brushId, String name, String mobile, String reason) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brushId);
        map.put("name", name);
        map.put("mobile", mobile);
        map.put("reason", reason);

        HttpUtils.doPost(URLs.agentApplyc, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //刷手  我的余额
    public static void userInfoc(final HttpOnNextListener listener, String brushId) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brushId);

        HttpUtils.doPost(URLs.userinfoc, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //刷手  我的余额
    public static void signC(final HttpOnNextListener listener, String brushId) {
        Map<String, String> map = new HashMap<>();
        map.put("brushId", brushId);

        HttpUtils.doPost(URLs.signc, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void chongzhimima(final HttpOnNextListener listener, String mobile, String captcha, String password, String repassword) {
        Map<String, String> map = new HashMap<>();
        int type = HbAppManager.getInstance().getTypeValue();
        map.put("type", type + "");
        map.put("mobile", mobile);
        map.put("captcha", captcha);
        map.put("password", password);
        map.put("repassword", repassword);

        HttpUtils.doPost(URLs.chongzhimima, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void getAgentnumList(final HttpOnNextListener listener, String brushId, String page, String size) {
        Map<String, String> map = new HashMap<>();
        map.put("agentId", brushId);
        map.put("page", page);
        map.put("size", size);

        HttpUtils.doPost(URLs.agentnumList, map, new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //修改密码
    public static void changePassword(final HttpOnNextListener listener, String brsuhId, String oldpwd, String pwd, String repwd) {
        Map<String, String> map = new HashMap<>();
        map.put("agentId", brsuhId);
        map.put("oldpwd", oldpwd);
        map.put("pwd", pwd);
        map.put("repwd", repwd);

        HttpUtils.doPost(URLs.changePassword, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    //修改密码
    public static void getVersion(final HttpOnNextListener listener, String brsuhId) {
        Map<String, String> map = new HashMap<>();
        map.put("appVersion", brsuhId);
        map.put("platform", "android");

        HttpUtils.doPost(URLs.changePassword, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

    public static void uploadError(final HttpOnNextListener listener, String brsuhId) {
        Map<String, String> map = new HashMap<>();
        map.put("content", brsuhId);

        HttpUtils.doPost(URLs.uploadError, map, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onNext("{\"status\":1000,\"message\":\"访问超时\",\"content\":\"访问超时\"}");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    listener.onNext(response.body().string());
                }
                //关闭防止内存泄漏
                if (response.body() != null) {
                    response.body().close();
                }
            }
        });
    }

}
